<?php
class UserFollowAction extends UAction
{
	public function __construct()
	{
		parent::__construct();
		$this->responseType = 'tpl';
		$this->layout = 'uindex';
	}
	
	public function execute()
	{
		$page = $this->getPage();
		$pagesize = 10;
		$followService  = new FollowService();
		$where 	= array('user_id'=>'eq:'.$this->data['master']['user_id']);
		$fields = array('id','user_id', 'follow_id');
		$result	= $followService->getList($where, 'id DESC', ($page-1)*$pagesize, $pagesize, $fields);
		$count	= $result['count'];
		$rows	= $result['rows'];
		if ($count){
			$ids 	= array();
			foreach($rows as $item){
				$ids[] = $item['follow_id'];
			}
			$weiboService = new WeiboService();
			$userService = new UserService();
			$users = $userService->getListByIds($ids);
			foreach($rows as $k=>$item){
				if (isset($users[$item['follow_id']])){
					$rows[$k]['username'] = $users[$item['follow_id']]['username'];
					$rows[$k]['logo'] 	  = $users[$item['follow_id']]['logo'];
					$rows[$k]['fans_num'] = $users[$item['follow_id']]['fans_num'];
					$con = array(
						'where'=>array('user_id'=>$item['follow_id']),
						'orderby'=>' id DESC ',
						'fields'=>array('content','created'),
					);
					$tmp = $weiboService->rows($con,1,1);
					if ($tmp){
						$tmp = $tmp[0];
						$tmp['created']    = Util::getBeforeTimelag(strtotime($tmp['created']));
						$rows[$k]['weibo'] = $tmp;
					}
					$rows[$k]['is_follow'] = $this->isFollow($item['follow_id']);
				}
			}
			$ltConfig		= C('LtConfig');
			$pagerConfig	= $ltConfig->get('pagination.pager');
			$baseUrl 		= C('LtUrl')->generate('Default', 'Index', array('module'=>'Share','action'=>'Follow','id'=>$share_id,'p' => ':page'));
			$pagination 	= new PiscesPagination;
			$pagination->init($pagerConfig);
			$this->data['pages'] = $pagination->pager($page, $count, $baseUrl);
		}
		$this->data['item'] = $rows;
	}
}
